package com.medical.doctor.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.medical.doctor.controller.vo.LivesVo;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.medical.doctor.entity.DoctorLiveEntity;
import com.medical.doctor.service.DoctorLiveService;
import com.medical.common.utils.PageUtils;
import com.medical.common.utils.R;



/**
 * 
 *
 * @author wen
 * @email 1023076426@qq.com
 * @date 2021-08-20 22:52:23
 */
@RestController
@RequestMapping("doctor/doctorlive")
public class DoctorLiveController {
    @Autowired
    private DoctorLiveService doctorLiveService;

    /**
     * 创建直播间
     */
    @PostMapping("/live/{id}")
    public R createLive(@PathVariable("id") Integer doctorId,@RequestBody DoctorLiveEntity doctorLiveEntity){
        doctorLiveService.createLive(doctorId,doctorLiveEntity);
        return R.ok();
    }

    /**
     * 再次直播
     * @param id
     * @return
     */

    @PostMapping("/liveon/{id}")
    public R liveagain(@PathVariable("id")Integer id){
        Boolean b=doctorLiveService.liveagain(id);
        if(b){
            return R.ok();
        }else {
            return R.error("该直播已失效");
        }
    }

    /**
     * 直播管理统计
     */
    @GetMapping("/lives/{id}")
    public R liveCount(@PathVariable("id")Integer doctorId){
        List<LivesVo> livesVos=doctorLiveService.lives(doctorId);
        return R.ok().setData(livesVos);
    }




    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = doctorLiveService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{liveId}")
    public R info(@PathVariable("liveId") Integer liveId){
		DoctorLiveEntity doctorLive = doctorLiveService.getById(liveId);

        return R.ok().put("doctorLive", doctorLive);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody DoctorLiveEntity doctorLive){
		doctorLiveService.save(doctorLive);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody DoctorLiveEntity doctorLive){
		doctorLiveService.updateById(doctorLive);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] liveIds){
		doctorLiveService.removeByIds(Arrays.asList(liveIds));

        return R.ok();
    }

}
